package com.epsoft.odin7cj.flow.example;

import java.util.HashMap;
import java.util.Map;

import org.activiti.engine.ProcessEngine;
import org.activiti.engine.ProcessEngines;
import org.activiti.engine.RepositoryService;
import org.activiti.engine.RuntimeService;
import org.activiti.engine.TaskService;
import org.activiti.engine.repository.Deployment;
import org.activiti.engine.repository.ProcessDefinition;
import org.activiti.engine.runtime.ProcessInstance;
import org.activiti.engine.task.Task;

public class T05ConditionGateway {

	public static void main1(String[] args) {
		
		ProcessEngine engine = ProcessEngines.getDefaultProcessEngine();
		
		RepositoryService rs = engine.getRepositoryService();
		
		TaskService ts = engine.getTaskService();
		
		RuntimeService rus = engine.getRuntimeService();
		
		Deployment deploy = rs.createDeployment().addClasspathResource("bpmn/t05-condition-gateway.bpmn").deploy();
		
		ProcessDefinition  pd = rs.createProcessDefinitionQuery().deploymentId(deploy.getId()).singleResult();
		
		Map<String,Object> paramMap = new HashMap<String,Object>();
		paramMap.put("days", 5);
		
		ProcessInstance pi = rus.startProcessInstanceById(pd.getId(),paramMap); 
		
		Task task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		
		System.out.println("当前节点："+task.getName());
		
		ts.complete(task.getId());
		
        task = ts.createTaskQuery().processInstanceId(pi.getId()).singleResult();
		
		System.out.println("当前节点："+task.getName());

	}

}
